/**
 * MenuManager.java
 *
 * Roslan's Remake of MOO in 3D using Ardor3D
 * (C) 2011 Roslan Amir. All rights reserved.
 */

package com.roslan.games.moo3d.ui.menu;

import com.roslan.games.moo3d.Main;

/**
 * This class manages the menu frames/panels.
 * 
 * @author Roslan Amir
 * @version 1.0 - Aug 10, 2011
 */
public class MenuManager {

	/**
	 * The singleton instance of this class.
	 */
	private static MenuManager instance;

	/**
	 * Reference to the single Main Menu frame.
	 */
	private MenuFrameMainMenu menuFrameMainMenu;

	/**
	 * Reference to the single Load Game Menu frame.
	 */
	private MenuFrameLoadGame menuFrameLoadGame;

	/**
	 * Reference to the single New Game Menu frame.
	 */
	private MenuFrameNewGame menuFrameNewGame;

	/**
	 * Reference to the single Choose Race Menu frame.
	 */
	private MenuFrameChooseRace menuFrameChooseRace;

	/**
	 * Reference to the single Choose Banner Menu frame.
	 */
	private MenuFrameChooseBanner menuFrameChooseBanner;

	/**
	 * Reference to the single Choose Leader Name Menu frame.
	 */
	private MenuFrameChooseLeaderName menuFrameChooseLeaderName;

	/**
	 * Reference to the single Choose Home Star Menu frame.
	 */
	private MenuFrameChooseHomeStar menuFrameChooseHomeStar;

	/**
	 * Reference to the single Options Menu frame.
	 */
	private MenuFrameOptions menuFrameOptions;

	/**
	 * Reference to the currently displayed Menu frame.
	 */
	private MenuFrameBase currentMenuFrame;

	/**
	 * Private Constructor.
	 */
	private MenuManager() {
	}

	/**
	 * Returns the singleton instance of this class.
	 * 
	 * @return the singleton instance of this class
	 */
	public static MenuManager getInstance() {
		if (instance == null) {
			instance = new MenuManager();
		}
		return instance;
	}

	/**
	 * Show the Main Menu
	 */
	public void showMainMenuFrame() {
		showMenu(menuFrameMainMenu);
	}

	/**
	 * Show the Load Game Menu
	 */
	public void showLoadGameFrame() {
		if (menuFrameLoadGame == null)
			menuFrameLoadGame = new MenuFrameLoadGame();
		menuFrameLoadGame.update();
		showMenu(menuFrameLoadGame);
	}

	/**
	 * Show the New Game Menu
	 */
	public void showNewGameFrame() {
		if (menuFrameNewGame == null)
			menuFrameNewGame = new MenuFrameNewGame(Main.camera);
		menuFrameNewGame.update();
		showMenu(menuFrameNewGame);
	}

	/**
	 * Show the Choose Race Menu
	 */
	public void showChooseRaceFrame() {
		if (menuFrameChooseRace == null)
			menuFrameChooseRace = new MenuFrameChooseRace();
		menuFrameChooseRace.update();
		showMenu(menuFrameChooseRace);
	}

	/**
	 * Show the Choose Banner Menu
	 */
	public void showChooseBannerFrame() {
		if (menuFrameChooseBanner == null)
			menuFrameChooseBanner = new MenuFrameChooseBanner();
		menuFrameChooseBanner.update();
		showMenu(menuFrameChooseBanner);
	}

	/**
	 * Show the Choose Leader Name Menu
	 */
	public void showChooseLeaderNameFrame() {
		if (menuFrameChooseLeaderName == null)
			menuFrameChooseLeaderName = new MenuFrameChooseLeaderName();
		menuFrameChooseLeaderName.update();
		showMenu(menuFrameChooseLeaderName);
	}

	/**
	 * Show the Choose Home Star Menu
	 */
	public void showChooseHomeStarFrame() {
		if (menuFrameChooseHomeStar == null)
			menuFrameChooseHomeStar = new MenuFrameChooseHomeStar();
		menuFrameChooseHomeStar.update();
		showMenu(menuFrameChooseHomeStar);
	}

	/**
	 * Show the Options Menu
	 */
	public void showOptionsFrame() {
		if (menuFrameOptions == null)
			menuFrameOptions = new MenuFrameOptions(Main.camera);
		menuFrameOptions.update();
		showMenu(menuFrameOptions);
	}

	/**
	 * Switch the currently displayed menu frame with the given one.
	 * 
	 * @param menuFrameBase the menu to show
	 */
	public void showMenu(MenuFrameBase menuFrameBase) {
		if (currentMenuFrame != null)
			Main.hud.remove(currentMenuFrame);
		Main.hud.add(menuFrameBase);
		currentMenuFrame = menuFrameBase;
	}

	/**
	 * Hide the currently displayed menu.
	 */
	public void hideMenu() {
		if (currentMenuFrame != null)
			Main.hud.remove(currentMenuFrame);
		currentMenuFrame = null;
	}

	/**
	 * Show the Main Menu frame.
	 * 
	 * @param camera - the camera to use
	 * @param Main.hud - the UIHud instance
	 */
	public void init() {
		menuFrameMainMenu = new MenuFrameMainMenu();
		showMainMenuFrame();
	}

}
